﻿//
// *************************************************************************************
// WP-Framework
// 
// Developed by
// Lukas Kretschmar (lkretschmar.dev@bluewin.ch)
//
// Switzerland, Copyright (c) 2013 lkretschmar
// This content is released under the MIT License (http://opensource.org/licenses/MIT).
//     
// *************************************************************************************
//
//



using Microsoft.VisualStudio.TestTools.UnitTesting;
using KretschIT.WP_Fx.EasyMoq.Generator.Arguments;
using KretschIT.WP_Fx.EasyMoq.Generator.Tests.Helpers.Objects;
using System.Linq;
using System;
using System.Collections.Generic;
using KretschIT.WP_Fx.EasyMoq.Generator.Items;

namespace KretschIT.WP_Fx.EasyMoq.Generator.Tests.Arguments
{
    [TestClass]
    public class GenericArgumentBuilderTest
    {
        private IGenericArgumentBuilder builder;

        [TestInitialize]
        public void Init()
        {
            this.builder = new GenericArgumentBuilder(new NamingFactory(new List<Type>())); 
        }

        [TestMethod]
        public void Test_SimpleAbstractGenericArgument()
        {
            var type = typeof(ITestGenericMethod);
            var method = type.GetMethod("GenericArgument");

            this.builder.Add(method.GetGenericArguments().Single());

            Assert.AreEqual("<T>", this.builder.String);
        }

        [TestMethod]
        public void Test_SimpleTypeGenericArgument()
        {
            var type = typeof(int);

            this.builder.Add(type);

            Assert.AreEqual("<System.Int32>", this.builder.String);
        }

        [TestMethod]
        public void Test_NonArgument()
        {
            Assert.AreEqual(string.Empty, this.builder.String);

            this.builder.Add(null);

            Assert.AreEqual(string.Empty, this.builder.String);
        }

        [TestMethod]
        public void Test_MultipleTypeArguments()
        {
            var types = new List<Type> { typeof(int), typeof(string), typeof(bool) };

            foreach (var t in types)
            {
                this.builder.Add(t);
            }

            Assert.AreEqual("<System.Int32, System.String, System.Boolean>", this.builder.String);
        }

        [TestMethod]
        public void Test_MultiGenericArguments()
        {
            var type = typeof(ITestGenericMethod);
            var method = type.GetMethod("MultiGenericArgument");

            foreach (var t in method.GetGenericArguments())
            {
                this.builder.Add(t);
            }

            Assert.AreEqual("<T1, T2>", this.builder.String);
        }

        [TestMethod]
        public void Test_ComplexGenericArgument()
        {
            var type = typeof(IEnumerable<IEnumerable<bool>>);

            foreach (var t in type.GetGenericArguments())
            {
                this.builder.Add(t);
            }

            Assert.AreEqual("<System.Collections.Generic.IEnumerable<System.Boolean>>", this.builder.String);
        }
    }
}
